package com.matt.repository.courseV2;

import com.matt.domain.courseV2.GrowthObservationRecord;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import io.lettuce.core.dynamic.annotation.Param;

import java.util.List;

@Repository
public interface GrowthObservationRecordRepository extends JpaRepository<GrowthObservationRecord, String>, JpaSpecificationExecutor<GrowthObservationRecord> {

    @Query(value ="SELECT *  FROM tc_growth_record " +
            "  WHERE  childrenId = :childrenId  and classesId = :classesId " +
            "  AND   if(:monthAge  != null, monthAge = :monthAge, 1=1)    AND   if(:states  != null, states = :states, 1=1)     ",nativeQuery = true)
    List<GrowthObservationRecord> findByChildrenAll(@Param("childrenId")String childrenId,@Param("classesId")String classesId,@Param("monthAge")Integer monthAge,@Param("states")String states);


    GrowthObservationRecord findByChildrenIdAndMonthAge(String childrenId,Integer monthAge);


    List<GrowthObservationRecord> findByChildrenId(String childrenId);
}